//
//  ViewController.m
//  UI_14_homework_UICollectionView
//
//  Created by li cheng on 16/8/2.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "ColumnsOfCollectionViewCell.h"
#import "ClassfiyCollectionViewCell.h"
#import "ColumnsCollectionReusableView.h"
#import "ClassfiyCollectionReusableView.h"
@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"攻略", @"单品"]];
    segment.frame = CGRectMake(0, 0, 200, 40);
    self.navigationItem.titleView = segment;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat width = CGRectGetWidth(self.view.bounds);
    CGFloat height = (width - 10) / 3;
    layout.itemSize = CGSizeMake( (width - 10) / 2, height);
    UICollectionView *colllectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    colllectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:colllectionView];
    // 指定代理人
    colllectionView.delegate = self;
    colllectionView.dataSource = self;
    // 注册cell
    [colllectionView registerClass:[ColumnsOfCollectionViewCell class] forCellWithReuseIdentifier:@"pool"];
    [colllectionView registerClass:[ClassfiyCollectionViewCell class] forCellWithReuseIdentifier:@"pool1"];
    // 注册头视图
    [colllectionView registerClass:[ColumnsCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool3"];
    [colllectionView registerClass:[ClassfiyCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool4"];
    
}
#pragma mark - 代理方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) {
        return 0;
    } else {
        return 10;
    }
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ClassfiyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool1" forIndexPath:indexPath];
    return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0){
        ColumnsCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool3" forIndexPath:indexPath];
        return reusableView;
    }else{
        ClassfiyCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool4" forIndexPath:indexPath];
        return reusableView;
    }
}
#pragma mark - 自定义item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return CGSizeMake(0, 450);
    } else {
        return CGSizeMake(0, 50);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
